/**
 * @description 朋友圈 router
 * @author malin
 */

const router = require('koa-router')()
const { createPyq, getPyqList } = require('../../controllers/pyq')
const genValidator = require('../../middlewares/validator')
const pyqValidator = require('../../validator/pyq')

router.prefix('/api/pyq')

router.get('/list/:page', async (ctx, next) => {
    const { page } = ctx.params
    const { userName } = ctx.state.user
    ctx.body = await getPyqList(userName, page)
})

router.post('/create', genValidator(pyqValidator), async (ctx, next) => {
    const { content, image } = ctx.request.body
    let userInfo = ctx.state.user
    ctx.body = await createPyq({ userId: userInfo.id, content, image})
})

module.exports = router
